package com.guigu.alibaba.controller;


import com.guigu.alibaba.service.AccountService;
import com.guigu.springcloud.common.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Resource
    private AccountService accountService;

    @GetMapping(value = "/decrease", produces = "application/json; charset=utf-8")
    public CommonResult decrease(Long userId, BigDecimal money) {
        /*
        try{
           Thread.sleep(20000);
            accountService.decrease(userId, money);
            return CommonResult.voData(200, "扣减金额成功！", null);
        }catch (Exception e){
            e.printStackTrace();
        }
        return CommonResult.voData(400, "扣减金额失败！", null);
        */
        accountService.decrease(userId, money);
        return CommonResult.voData(200, "扣减金额成功！", null);
    }
}
